<?php

declare(strict_types=1);

namespace app\core;

use Exception;
use Throwable;

class ExceptionHandler extends Exception
{


    public $code = 500;

    // Redefine the exception so message isn't optional
    public function __construct($message, $code = 0, Throwable $previous = null)
    {
        // some code
        $code = $this->code;
        // make sure everything is assigned properly
        parent::__construct($message, $code, $previous);
    }

    // custom string representation of object
    public function __toString()
    {
        return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
    }

    public  function record()
    {
        $dt = date("Y-m-d");
        $dtError = date("Y-m-d H:i:s");
        $message = "[{$dtError}]{$this->message} {$this->getFile()} {$this->getLine()}";
        error_log($message . "\r\n", 3, LOG . "{$dt}.log");
    }
}
